home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / MPW Oberon 2.1168 / OExamples / EditCDEV.mod < prev    next >
Encoding:
Text File  |  1995-07-03  |  4.8 KB  |  142 lines  |  [TEXT/MPS ]

  1. (*------------------------------------------------------------------------------
  2. #
  3. #    Macintosh Developer Technical Support
  4. #
  5. #    EditText Sample Control Panel Device
  6. #
  7. #    EditCDEV
  8. #
  9. #    EditCDEV.p    -    Pascal Source
  10. #
  11. #    Copyright © 1988 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    1.0                    8/88
  15. #
  16. #    Components:    EditCDEV.p            August 1, 1988
  17. #                EditCDEV.r            August 1, 1988
  18. #                EditCDEV.make        August 1, 1988
  19. #
  20. #    EditCDEV is a sample Control Panel device (cdev) that 
  21. #    demonstrates the usage of the edit-related messages.  
  22. #    EditCDEV demonstrates how to implement an editText item
  23. #    in a Control Panel Device.  It utilizes the new undo, cut, copy,
  24. #    paste, and delete messages that are sent to cdevs in
  25. #    response to user menu selections.
  26. #
  27. #    It is comprised of two editText items that can be edited 
  28. #    and moved between via the mouse or tab key.
  29. #
  30. ------------------------------------------------------------------------------*)
  31.  
  32.  
  33. MODULE EditCDEV;
  34.  
  35. IMPORT SYSTEM, Types, Memory, Events, Dialogs, Devices;
  36.  
  37. CONST
  38.  
  39.     textItm        = 1;            (*first editTExt item in cdev*)
  40.  
  41. TYPE
  42.  
  43.     CDEVRec    = RECORD
  44.                 dummyData    : INTEGER;
  45.                 END;
  46.     (*CDEVPtr    = POINTER TO CDEVRec;
  47.     CDEVHnd    = HANDLE TO CDEVRec;*)
  48.  
  49. (*$S Main*) (* put routines in segment "Main"*)
  50.  
  51. PROCEDURE ^DoEditCommand(message: INTEGER; CPDialog: Dialogs.DialogPtr);
  52.  
  53. (*$Calling Pascal*)
  54. PROCEDURE TextCDEV*(message, item, numItems, CPanelID: INTEGER;
  55.                     VAR theEvent: Events.EventRecord;
  56.                     cdevStorage: Types.Handle;
  57.                     CPDialog: Dialogs.DialogPtr) : Types.Handle;
  58. (*This is the main dispatcher. It must be the first code in the cdev.
  59.  EditCDEV's dispatcher responds only to the following messages from
  60.  the Control Panel:
  61.      
  62.     macDev        - To indicate what machines it is available on.
  63.     initDev        - To set up some temporary storage and get the caret started.
  64.     keyEvtDev    - To check for an edit command and do the appropriate action.
  65.     cutDev        - To cut the current selection.
  66.     copyDev        - To copy the current selection.
  67.     pasteDev    - To paste the contents of the clipboard.
  68.     clearDev    - To delete the current selection.
  69.  
  70.  The Dialog Manager's services are used to handle entry of text, selection
  71.  of text, editing of text, and moving between the editText items via the
  72.  tab key. Since the Dialog Manager handles the selection of text, we do not
  73.  have to be concerned with hitDev messages for the editText items. The only
  74.  things we have to take care of are calling the Dialog Manager editing
  75.  routines in response to an edit command, and getting the caret to show up
  76.  at the beginning. In response to an edit command that was the result of
  77.  a command-key equivalent, we must also eliminate the event so that it does
  78.  not get processed as a keyDown by the Dialog Manager. Otherwise, an 'x'
  79.  would show up in the editText item when the user did a command-x to cut
  80.  the text.*)
  81.  
  82. VAR
  83.     tempChar    : CHAR;
  84. BEGIN
  85. IF message = Devices.macDev THEN
  86.     RETURN Types.Handle(1)            (*we work on every machine*)
  87. ELSIF cdevStorage # NIL THEN
  88.     CASE message OF
  89.     Devices.initDev:                                            (*initialize cdev*)
  90.         cdevStorage := Memory.NewHandle(SIZE(CDEVRec));        (*create private storage*)
  91.         Dialogs.SelIText(CPDialog, numItems + textItm, 0, 999)|    (*make caret show up*)
  92.     Devices.hitDev:|
  93.     Devices.closeDev:|
  94.     Devices.nulDev:|
  95.     Devices.updateDev:|
  96.     Devices.activDev:|
  97.     Devices.deactivDev:|
  98.     Devices.keyEvtDev:                                            (*respond to key down*)
  99.         (*first, get the character*)
  100.         tempChar := CHR(BAND(theEvent.message, Events.charCodeMask));
  101.         (*then see if the command key was down*)
  102.         IF BAND(theEvent.modifiers, Events.cmdKey) # 0 THEN
  103.             message := Devices.nulDev;                            (*start off with no message*)
  104.             theEvent.what := Events.nullEvent;                    (*wipe out event*)
  105.             CASE CAP(tempChar) OF                            (*set appropriate message*)
  106.                 'X': message := Devices.cutDev|
  107.                 'C': message := Devices.copyDev|
  108.                 'V': message := Devices.pasteDev|
  109.                 ELSE (* ignore other characters *)
  110.             END;
  111.             DoEditCommand(message, CPDialog);            (*let edit command handler take it*)
  112.         END|
  113.     Devices.macDev:|
  114.     Devices.undoDev:|
  115.     Devices.cutDev, Devices.copyDev, Devices.pasteDev, Devices.clearDev:
  116.         DoEditCommand(message, CPDialog)|                (*respond to edit command*)
  117.     ELSE (* ignore other messages *)
  118.     END;  (*CASE message*)
  119.     RETURN cdevStorage;
  120.     (*if cdevStorage = NIL then ControlPanel will put up memory error*)
  121.     END;  (*cdevStorage <> NIL*)
  122. RETURN NIL
  123. END TextCDEV;
  124. (*$Calling Oberon*)
  125.  
  126. PROCEDURE DoEditCommand (message: INTEGER; CPDialog: Dialogs.DialogPtr);
  127.  
  128. (*Call the apprpriate Dialog Manager routine to handle an edit command for
  129.  an editText item. It will do all the work regarding the TEScrap.*)
  130.  
  131. BEGIN
  132. CASE message OF
  133.     Devices.cutDev: Dialogs.DlgCut(CPDialog)|
  134.     Devices.copyDev: Dialogs.DlgCopy(CPDialog)|
  135.     Devices.pasteDev: Dialogs.DlgPaste(CPDialog)|
  136.     Devices.clearDev: Dialogs.DlgDelete(CPDialog)|
  137.     ELSE (* ignore other messages *)
  138. END
  139. END DoEditCommand;
  140.  
  141. END EditCDEV.
  142.